{

  I2C Slave object for the Parallax Propeller

  Written by Daniel Harris

  Started: 1/20/2012

  === Descrition and Idea ===
  This program is intended to be loaded on a Propeller based board that
  will act as a protocol translator and buffer for the CMUcam.

  Upon request by the host processor (Gumstix CoM in Acroname Garcia robot)
  via I2C protocol, this translator will make appropriate serial requests to
  the CMUcam.  The CMUcam should take a picture and then dump the frame
  back to the translator, at which point the translator will buffer up the
  image into Hub RAM.  Finally, the host processor can request an image dump
  via I2C.  The translator will respond with

}

con

  _xinfreq = 5_000_000
  _clkmode = xtal1 + pll16x

  
  SDA_PIN       =       28
  SCL_PIN       =       29


obj

'  i2c   :       "new_i2c"
'  ser   :       "FullDuplexSerial"

var

  long image_buff[2860]         '80 x 143 pixels @ 1 byte per pixel = 11,440 bytes / 4 bytes per long = 2860 longs

pub go


dat


                        org
i2c_slave

                        'init system and state machine

                        mov     scl_mask,#1
                        shl     scl_mask,#SCL_PIN
                        mov     sda_mask,#1
                        shl     sda_mask,#SDA_PIN

                        mov     t0,scl_mask
                        or      t0,sda_mask
                        andn    dira,t0                 'float the pins
                        andn    outa,t0                 'set pin states low for data IO, driven low when active


                        'state 0: wait for start command

wait_for_start
                        test    ina,scl_mask    wz
              if_z      jmp     #wait_for_start
                        
                        test    ina,sda_mask    wz
              if_z      



t0                      res     1
t1                      res     1
t2                      res     1
t3                      res     1

scl_mask                res     1
sda_mask                res     1
